<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery-2.1.1.min.js"></script>
    <script src="/js/my97/WdatePicker.js"></script>
    <link rel="stylesheet" href="/js/uploadify/uploadify.css" />
    <script src="/js/uploadify/jquery.uploadify.min.js"></script>

    <link rel="stylesheet" href="/js/kindeditor-4.1.10/themes/default/default.css" />
    <script src="/js/kindeditor-4.1.10/kindeditor-all.js"></script>

    <link rel="stylesheet"href="/js/easyui1.5/themes/default/easyui.css"type="text/css"></link>
    <link rel="stylesheet"href="/js/easyui1.5/themes/icon.css"type="text/css"></link>
    <script type="text/javascript" src="/js/easyui1.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/easyui1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<input type="hidden" th:values="${msg}" id="mg">
<a id="btn_add" onclick="addData()" href="javascript:void(0)"class="easyui-linkbutton" data-options="iconCls:'icon-remove'">增加</a>

<table id="dg"  width="100%" >

</table>
<!-- 弹框增加start -->
<div id="dialog_add" class="easyui-dialog" title="My Dialog"
     style="width:800px;height:400px;"
     data-options="iconCls:'icon-save',resizable:true,modal:true,
				buttons:[{
					text:'保存',
					iconCls:'icon-no',
					handler:function(){
						submitData()//调用另一个方法
					}
				},{
					text:'关闭',
					iconCls:'icon-more',
					handler:function(){
						closedSubmitData()
						 $('#dialog_add').dialog('close');
					}
				}]">
    <form id="add_form">
        <input type="hidden" name="id">
        权限:<input name="text" class="easyui-textbox" data-options="iconCls:'icon-man'" style="width:200px"><br>
        路径：<input name="url" class="easyui-textbox" data-options="iconCls:'icon-man'" style="width:200px"><br>
    </form>
</div>

</body>
 <script type="text/javascript" th:inline="none">
     $(function(){
         $('#dialog_add').dialog('close');

         getRle();

     //=====新增
         normal2ajax();




     })

     function getRle(){
         $("#dg").datagrid({
             url:'/view/queryPer',
             pagination:true,
             pageList:[5,7,10],
             pageSize: 5,
              rowStyler: function(index,row){
                 if (index%2==0){
                     return 'background-color:#6293BB;color:#fff;';
                 }else{
                     return "background-color:#ccffff;color:red;";
                 }
             },
             /* 奇数偶数行不同颜色 end */
             columns:[[
                 {field:'xxx',title:'复选框',width:100,checkbox:true},
                 {field:'id',title:'ID',width:100},
                 {field:'text',title:'权限名字',width:100,editor:'text'},
                 {field:'xxx1',title:'操作',width:100,
                     /* 操作start */
                     formatter: function(value,row,index){
                         var content="<a href='javascript:void(0)' onclick=updaPer("+row.id+")>修改</a>";
                         content+=" | <a href='javascript:void(0)' onclick=deleteItemsById("+row.id+")>删除</a>";
                         return content;
                     }
                     /* 操作end */
                 },
             ]],
             checkOnSelect:false,
         })
     }

     function deleteItemsById(id){
         $.messager.confirm('确认','您确认想要删除这个权限记录吗？',function(r){
             if (r){//点击确认
                 deleteItems(id);
             }
         });
     }

     function deleteItems(ids){
         $.ajax({
             url:"/view/delPer",
             type:"POST",
             data:{id:ids},
             success:function(pageUtil){
                 /* deleteItems start */
                 $.messager.show({
                     title:'删除',
                     msg:'删除成功',
                     timeout:2000,
                     showType:'slide'
                 });
                 getRle();
             },
             error:function(pageUtil){
                 if(pageUtil==0){
                     alert("代码错误");
                 }else{
                     alert("删除失败");
                 }
             }
         });
     }
     /* 修改start */
     function updaPer(id){
         $.ajax({
             url:"/view/updaPer",
             type:"POST",
             data:{id:id},
             success:function(result){
                 $("#dialog_add").dialog("open");
                 $('#add_form').form('load',result);
             },
             error:function(){
                 alert("失败了");
             }
         });
     }
     /* 修改end */
     /* 提交================================================> start*/
     function normal2ajax(){
         $('#add_form').form({
             url:'/view/addPer',
             onSubmit: function(){
             },
             success:function(data){
                 if(data==1){
                     alert("不能添加重复的编号");
                 }else{
                     closedSubmitData();
                     $("#dialog_add").dialog("close");
                     $('#dg').datagrid('reload');
                 }
             }
         });
     }
     function submitData(){//进行提交表单
         $("#add_form").form('submit')
     }
     function addData(){
         $("#dialog_add").dialog("open");
         closedSubmitData();
     }
     function closedSubmitData(){
         $('#add_form').form("clear");
     }
 </script>
</html>